//axios 是从axios中引入的
//渲染列表
function render(data) {
    var str = ''
    str = data.map((item,index)=>{
        return ` <tr>
        <td>${item.email}</td>
        <td>${item.name}</td>
        <td>${item.phone}</td>
        <td>${item.ingroup}</td>
        <td>${item.admin ? '是' : '否'}</td>
        <td><span class="${item.status ? 'status' : 'active' }">${item.status ? '正常' : '异常'}</span></td>
        <td><span class="iconfont icon-bianji"></span> <span class="iconfont icon-shanchu"></span></td>
    </tr>`
    }).join('')
    if(str=='') {
        document.querySelector('tbody').innerHTML = `<tr style="text-align:center;color:red">未查询到</tr>`
    } else {
        document.querySelector('tbody').innerHTML = str
    }
}
let page = 1;
let count = 2
let next = document.querySelector('.next')
let prev = document.querySelector('.prev')

if(page==1) {
    prev.disabled = true
    axios.get('./user/list',{params: { page,count }}).then((res)=>{
        render(res.data.list)
        console.log(res.data.list);
    })
}

next.onclick = function() {
    prev.disabled = false
    if(page<1) {
        page++
        
    } else {
        page=2
        next.disabled = true
    }
    axios.get('./user/list',{params: { page,count }}).then((res)=>{
        render(res.data.list);
        console.log(page);
    })
}
prev.onclick = function() {
    next.disabled = false
    page--
    if(page==1) {
        prev.disabled = true
    }  
    axios.get('./user/list',{params: { page,count }}).then((res)=>{
        render(res.data.list)
    })
}

//模糊搜索
let searchbox = document.querySelector('.sousuokuang')
let searchbtn = document.querySelector('.sousuo')
searchbtn.onclick = () => {
    axios.get('/user/search',{params:{searchkey:searchbox.value}}).then((res)=>{
        render(res.data.list)
    })
}

axios.post('./user/login',{phone:'13991281021',pass:'1234'}).then((res)=>{
    console.log(res.data);
})